from python_baway.common.xcommon import xcheck, sep


def MergeByUpdate(dict1, dict2):
    dict1.update(dict2)
    return dict1


def MergeByDoubleAsterisk(dict1, dict2):
    return {**dict1, **dict2}


def MergeByUnion(dict1, dict2):
    return dict1 | dict2


x1 = zip('abcd', range(1, 1 + 4))
xcheck(x1, 'x1')
d1 = dict(x1)
xcheck(d1, 'd1')
x2 = zip('cdef', range(11, 1 + 44))
xcheck(x2, 'x2')
d2 = dict(x2)
xcheck(d2, 'd2')

sep('merge by update')
d3 = d2.copy()
xcheck(d3, 'd3')
d3 = MergeByUpdate(d1, d2)
xcheck(d1, 'd1')
xcheck(d2, 'd2')
xcheck(d3, 'd3')

sep('merge by double asterisks')
d4 = MergeByDoubleAsterisk(d1, d2)
xcheck(d1, 'd1')
xcheck(d2, 'd2')
xcheck(d4, 'd4')

sep('merge by union')
d5 = MergeByUnion(d1, d2)
xcheck(d1, 'd1')
xcheck(d2, 'd2')
xcheck(d5, 'd5')
